#include <stdio.h>
#include <string.h>



int main()
{
	/* ppp1.1,;192.168.1.0/24,;221.4.102.162,210.51.176.71,;tr69c */ 
	FILE *fp;
	char line[128] = {0};
	char dnsList[128] = {0};
	char services[32] = {0};
	char *nullPtr;
	char *curPtr;
	if ((fp = fopen("dnsinfo.conf", "r")) == NULL)
	{
		printf(" dnsinfo.conf does not exist.\n");
		return -1; 
	}

	while (fgets(line, sizeof(line), fp))
	{
	      if (line[strlen(line) -1] == '\n')
	      {
		 line[strlen(line) - 1] = '\0';
	      }
		curPtr = line;
		/* 1) get Wan IfName */
		if ((nullPtr = strchr(curPtr, ';')) != NULL)
		{
			curPtr = nullPtr + 1;         
		}

		/* 2) get subnet in cidr format */
		if ((nullPtr = strchr(curPtr, ';')) != NULL)
		{
			curPtr = nullPtr + 1;         
		}

		/* 3)  get dns list separated by ',' */
		if ((nullPtr = strchr(curPtr, ';')) != NULL)
		{
			*nullPtr = '\0';
			strcpy(dnsList, curPtr);
			curPtr = nullPtr + 1;  
			printf("dnslist is %s curPrt %s\n", dnsList, curPtr);
		
			if(strcmp(curPtr, "tr69c") == 0)
			{
				nullPtr = dnsList;
				while(*nullPtr != ',')
				{
					nullPtr++;				
				}
				*nullPtr = '\0';
				printf("dnslist is %s \n", dnsList);
			}
			    
		}
	}
	fclose(fp);
	return 0;
}
